import unittest
import xigonimlib

test "sane division":
  check sdiv(123, 10) == 12
  check sdiv(-123, 10) == -13
  check sdiv(123, -10) == -13
  check sdiv(-123, -10) == 12
  check sdiv(120, 10) == 12
  check sdiv(-120, 10) == -12
  check sdiv(120, -10) == -12
  check sdiv(-120, -10) == 12

test "sane modulo":
  check smod(123, 10) == 3
  check smod(-123, 10) == 7
  check smod(123, -10) == -7
  check smod(-123, -10) == -3
  check smod(120, 10) == 0
  check smod(-120, 10) == 0
  check smod(120, -10) == 0
  check smod(-120, -10) == 0

test "sane division and modulo identity":
  for a in -1000..1000:
    for b in -100..100:
      if b != 0:
        check a.sdiv(b) * b + a.smod(b) == a

test "updateMin":
  var n = 5
  check not n.updateMin(8)
  check n == 5
  check n.updateMin(3)
  check n == 3
  check not n.updateMin(3)
  check n == 3

test "updateMax":
  var n = 5
  check not n.updateMax(3)
  check n == 5
  check n.updateMax(8)
  check n == 8
  check not n.updateMax(8)
  check n == 8
